home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / win-os2.swg / 0055_Protected Mode BIOS Example.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1995-02-28  |  4.4 KB  |  185 lines

  1. program BIOS;
  2. { Compile in protected mode only }
  3.  
  4. uses
  5.   Crt, WINAPI;
  6.  
  7. const
  8.   Coms:array[0..3] of String= ('Com1: ', 'Com2: ', 'Com3: ', 'Com4: ');
  9.   Lpts:array[0..2] of String= ('Lpt1: ', 'Lpt2: ', 'Lpt3: ');
  10.  
  11. type
  12.   PBios = ^TBios;
  13.   TBios = Record
  14.     SerialPortAdd    : Array [0..3] of Word;
  15.     ParallelPortAdd  : Array [0..3] of Word;
  16.     EqptFlags        : Word;
  17.     MfgrTestFlags    : Byte;
  18.     MainMem,
  19.     ExpRam,
  20.     KbdStat          : Word;
  21.     KeyPad           : Byte;
  22.     KbdBuffHead,
  23.     KbdBuffTail      : Word;
  24.     KbdBuff          : Array [0..31] of Char;
  25.     SeekStatus,
  26.     MortotStatus,
  27.     MortoCnt,
  28.     DiskError        : Byte;
  29.     NECStatus        : Array [0..6] of Byte;
  30.     VideoMode        : Byte;
  31.     ScrnWidth,
  32.     VideoBufferSize,
  33.     VideoBufferOfs   : Word;
  34.     CursorPos        : Array [0..7,0..1] of Byte;
  35.     CursorBottom,
  36.     CursorTop,
  37.     ActiveDisplayPage : Byte;
  38.     ActiveDisplayPort : Word;
  39.     CRTModeReg,
  40.     Palette           : Byte;
  41.     DataEdgeTimeCount,
  42.     CRCReg            : Word;
  43.     LastCharInput     : Char;
  44.     Tick              : Word;
  45.     Hour              : Integer;
  46.     TimerOverFlow,
  47.     BrkStatus         : Byte;
  48.     ResetFlag         : Word;
  49.     HardDiskStatus    : LongInt;
  50.     ParallelTimeout,
  51.     SerialTimeout     : Array[0..3] of Byte;
  52.     KbdBufferOfs,
  53.     KbdBufferEnd      : Word;
  54.   End;
  55.   AtBios = Record
  56.     Name : Array[0..164] of Char;
  57.   End;
  58.  
  59. var
  60.   SaveAttr: Byte;
  61.  
  62. Procedure CursorOff; assembler;
  63. asm
  64.   mov AH, $01;
  65.   mov CH, $20;
  66.   mov CL, $20;
  67.   int $10;
  68. End;
  69.  
  70. procedure CursorSmall;
  71. Begin
  72.   if LastMode <> CO80 then asm
  73.     mov AH, $01;
  74.     mov CH, 12;
  75.     mov CL, 13;
  76.     int $10;
  77.   end else asm;
  78.     mov AH, $01;
  79.     mov CH, $06;
  80.     mov CL, $07;
  81.     int $10;
  82.   end;
  83. end;
  84.  
  85. function GetHexWord(w: Word): String;
  86. const
  87.  hexChars: array [0..$F] of Char =
  88.    '0123456789ABCDEF';
  89. begin
  90.  GetHexWord := hexChars[Hi(w) shr 4] + hexChars[Hi(w) and $F] +
  91.                hexChars[Lo(w) shr 4] + hexChars[Lo(w) and $F];
  92. end;
  93.  
  94. procedure WriteXY(X, Y: Integer; S: String);
  95. begin
  96.   GotoXY(X, Y);
  97.   Write(S);
  98. end;
  99.  
  100. procedure WriteXY2(X, Y: Integer; S: String; W: Word);
  101. begin
  102.   GotoXY(X, Y);
  103.   Write(S);
  104.   Write(W);
  105. end;
  106.  
  107. procedure WriteXY3(X, Y: Integer; S: String; B: Boolean);
  108. begin
  109.   GotoXY(X, Y);
  110.   Write(S);
  111.   Write(B);
  112.   ClrEOL;
  113. end;
  114.  
  115. procedure WriteData(Ticks: PBios);
  116. var
  117.   SaveAttr, i: Integer;
  118.  
  119. begin
  120.   for i := 0 to 3 do
  121.     WriteXY(1, 1 + i, Coms[i] + GetHexWord(Ticks^.SerialPortAdd[i]));
  122.   for i := 0 to 2 do
  123.     WriteXY(1, 6 + i, Lpts[i] + GetHexWord(Ticks^.ParallelPortAdd[i]));
  124.   WriteLn;
  125.   WriteXY2(1, 10, 'VideoMode: ', Ticks^.VideoMode);
  126.   WriteXY2(1, 11, 'Dos Mem: ', Ticks^.MainMem);
  127.   WriteXY(1, 12, 'Video Card Port Addresss: ' +
  128.                  GetHexWord(Ticks^.ActiveDisplayPort));
  129.   WriteXY2(1, 13, 'Tick: ', Ticks^.Tick);
  130.   WriteXY2(1, 14, 'Hour: ', Ticks^.Hour);
  131.   WriteXY2(1, 15, 'Break Status: ', Ticks^.BrkStatus);
  132.   WriteXY2(1, 16, 'Palette: ', Ticks^.Palette);
  133.   WriteXY3(1, 18, 'Right Shift: ', 0 <> Ticks^.KbdStat and 1);
  134.   WriteXY3(1, 19, 'Left Shift: ', 0 <> Ticks^.KbdStat and 2);
  135.   WriteXY3(1, 20, 'Ctrl : ', 0 <> Ticks^.KbdStat and 4);
  136.   WriteXY3(1, 21, 'Alt: ', 0 <> Ticks^.KbdStat and 8);
  137.   WriteXY3(1, 22, 'Scroll Lock: ', 0 <> Ticks^.KbdStat and 16);
  138.   WriteXY3(1, 23, 'Num Lock: ', 0 <> Ticks^.KbdStat and 32);
  139.   WriteXY3(1, 24, 'Caps Lock: ', 0 <> Ticks^.KbdStat and 64);
  140.   GotoXY(1,25);
  141.   SaveAttr := TextAttr;
  142.   TextAttr := 0 + 7 * 16;
  143.   Write('Press Shift, Alt, Caps Lock, etc, to see status of keys ' +
  144.         '-- Any key to exit    ');
  145.   TextAttr := SaveAttr;
  146. end;
  147.  
  148. procedure Opening;
  149. begin
  150.   SaveAttr := TextAttr;
  151.   TextAttr := 7 + 1 * 16;
  152.   ClrScr;
  153.   GotoXY(1,25);
  154.   TextAttr := 0 + 7 * 16;
  155.   ClrEOL;
  156.   TextAttr := 7 + 1 * 16;
  157.   CursorOff;
  158. end;
  159.  
  160. function RealToProt(P : Pointer; Siz : Word;
  161.                     var Sel : Word) : Pointer;
  162. begin
  163.   SetSelectorBase(Sel,
  164.                  LongInt(HiWord(LongInt(P))) shl 4+
  165.                  LoWord(LongInt(P)));
  166.   SetSelectorLimit(Sel, Siz);
  167.   RealToProt := Ptr(Sel, 0);
  168. end;
  169.  
  170. var
  171.   Sel : Word;
  172.   Ticks : PBios;
  173. begin
  174.   Opening;
  175.   Sel := AllocSelector(DSeg);
  176.   Ticks := Ptr($0000, $400);
  177.   Ticks := RealToProt(Ticks, SizeOf(TBIOS), Sel);
  178.   repeat
  179.     WriteData(Ticks);
  180.   until KeyPressed;
  181.   FreeSelector(Sel);
  182.   CursorSmall;
  183.   TextAttr := SaveAttr;
  184. end.
  185.